//固定set赋予map进行初始值的使用，注意：map无论是set或者数组或者对象类型没有关系，但一定得是键值对
const set=new Set([['foo',1],['bar',2]]);
var m1=new Map(set);
console.log(m1.get('foo'));
console.log(m1.get('bar'));
var m2=new Map([['hha',3]]);
console.log(m2.get('hha'));
var m3=new Map(m2);
console.log(m3.get('hha'));

var dmap=new Map();
dmap.set('qu',5);
console.log(dmap.get('qu'));
//定义初始对象的值
var map0=new Map([[1,1],[2,2],[3,3],[4,4],[5,5],[6,6]]);
console.log(map0);
//用filer对map进行处理
var mulMap=new Map([[1,1],[2,2],[3,3],[4,4],[5,5],[6,6]].filter(([k,v])=>v<3));
console.log(mulMap);
//用map方法对键值进行操作
var mulMap2=new Map([[1,1],[2,2],[3,3],[4,4],[5,5],[6,6]].map(([k,v])=>[k*2,'_'+v]));
console.log(mulMap2);
//foreach的使用
mulMap2.forEach(function(value,key,map){
	console.log("value=%s,key=%s",value,key);
	//console.log(map);
});
//先定义一个对象然后通过遍历进行处理
const reporter={
	report:function(key,value){
		console.log("the sort is %s,the value is %s",key,value);
	}
	};
mulMap2.forEach(function(value,key,map){
	this.report(key,value);
},reporter);
const mulMap3=[...mulMap2]
console.log(mulMap3);
//map转对象的函数
function strMaptoObj(map){
	var obj=Object.create(null);
	for(var [k,v] of map){
		obj[k]=v;
	}
	return obj;
}
mulobject=strMaptoObj(mulMap2);
console.log(mulobject);
//对象转map操作
function strObjtoMap(obj){
	var emptyMap=new Map();
	for(var k of Object.keys(obj)){
		emptyMap.set(k,obj[k]);
	}
	return emptyMap;
}
var toMap=strObjtoMap({'errcode':0,'errmsg':'提交成功'});
console.log(toMap);
//map转json
function strMaptoJson(map){
	var toJson=JSON.stringify(strMaptoObj(map));
	return toJson
}
//var testMap={"name" => "zjh", "age" => "18"};
console.log(strMaptoJson(mulMap2));
//jsontoMap
function strJsontoMap(json){
	var toMap=strObjtoMap(JSON.parse(json));
	return toMap;
	
}
console.log(strJsontoMap('{"name":"zjh","age":18}'));